import axios from 'axios'

const DOMAIN = 'http://localhost:8080/'

// cause prefilght request if config:
// axios.defaults.headers.common['Access-Control-Allow-Headers'] = ['access-control-allow-headers', 'Content-Type', 'Access-Control-Max-Age']

axios.defaults.withCredentials = true
axios.defaults.headers.common['Access-Control-Max-Age'] = 86400
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

function GET_AUTH(token) {
    return axios.get(DOMAIN + 'auth/' + token)
}
function LOGIN(username, password) {
    let params = new URLSearchParams()
    params.append('username', username)
    params.append('password', password)
    return axios.post(DOMAIN + 'login', params)
}
function LOGOUT(token) {
    return axios.post(DOMAIN + 'logout/' + token)
}

export {
    GET_AUTH,
    LOGIN,
    LOGOUT
}